import Vue from 'vue'
import Vuex from 'vuex'
import shopCar from "@/netapi/shopcar/shopcar.js"
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    shopcar:"",
    showcoll:"",
    shopCar:[],
    carLength:""

  },
  mutations: {

  },
  actions: {
    getColllist(state,val){
      shopCar.colllist({
        openId:JSON.parse(window.localStorage.getItem("userInfo")).openId
      })
      .then(res=>{
      
      let num=  res.collectGoodsList.findIndex(el=>{
         return el.id == val
        })
       console.log(num);
       if (num !== -1) {
        this.state.showcoll = true
       }else{
        this.state.showcoll = false
       }
      })
    },
    getShopcar(){
      shopCar.Carlist({
        openId:JSON.parse(localStorage.getItem("userInfo")).openId
      }).then(res=>{
        // this.state.shopCar = res.data
        this.state.carLength = this.state.shopCar.length
        res.data.forEach(el=>{
          el.check = false
          this.state.shopCar.push(el)
        })
      })
    },
    delPro(state,val){
      shopCar.delPro({
        id:val
      }).then(res=>{
        console.log(res);
        
      })
    }
  },
  modules: {

  }
})
